#include "StdAfx.h"
#include "LineBuilder.h"
#include <BRepBuilderAPI_MakeEdge.hxx> 
#include "varlist.h"
#include "LabelTools.h"
#include "ShapeInfoFactory.h"

REGISTERE_SHAPEINFO(CLineInfo, LINE_TWO_CUID);
//////////////////////////////////////////////////////////////////////////
CLineInfo::CLineInfo()
{
	m_szGUID = LINE_TWO_CUID;
	Reset();
}
CLineInfo::~CLineInfo()
{
}
void CLineInfo::Reset()
{
	ptStart = ptEnd = gp_Pnt(0,0,0);
}
void CLineInfo::GetParams(CVarList& varList, UINT nID)
{
	varList.SetID(LINE_TWO_CUID);
	varList.SetValue(START_POINT, ptStart);
	varList.SetValue(END_POINT, ptEnd);
}
void CLineInfo::SetParams(const CVarList& varList, UINT nID)
{
	CPointProxy point;
	varList.GetValue(START_POINT, point);
	ptStart = point;
	varList.GetValue(END_POINT, point);
	ptEnd = point;

}
bool CLineInfo::GetFromLabel(TDF_Label& label)
{
	TDF_Label childLabel;

	if(!LabelTools::GetChild(label, START_POINT, ptStart, childLabel))
		return false;

	if(!LabelTools::GetChild(label, END_POINT, ptEnd, childLabel))
		return false;

	return true;
}

void CLineInfo::AddToLabel(TDF_Label& label)
{
	LabelTools::SetChild(label, START_POINT, ptStart);
	LabelTools::SetChild(label, END_POINT, ptEnd);

}

bool CLineInfo::ModifyLabel(TDF_Label& label, TFunction_Logbook& log)
{
	if(!LabelTools::UpdateChild(label, START_POINT, ptStart, log))
		return false;

	if(!LabelTools::UpdateChild(label, END_POINT, ptEnd, log))
		return false;

	return true;
}

bool CLineInfo::IsModified(TDF_Label& label,const TFunction_Logbook& log)
{
	if(log.IsModified(label.FindChild(START_POINT)))
			return true; 
	
	if(log.IsModified(label.FindChild(END_POINT)))
		return true; 

	return false;
}
//////////////////////////////////////////////////////////////////////////

CLineBuilder::CLineBuilder(void)
{
}

CLineBuilder::~CLineBuilder(void)
{
}

bool CLineBuilder::Build(const CString& szCmdParam, TopoDS_Shape& shape)
{
	return false;
}

bool CLineBuilder::Build(CLineInfo* pShapeInfo, TopoDS_Shape& shape)
{
	try
	{
		BRepBuilderAPI_MakeEdge builder(pShapeInfo->ptStart, pShapeInfo->ptEnd);
		shape = builder.Shape();
	}
	catch (...) 
	{
		return false;
	}

	return true;
}